<?php include 'inc/super_head.php';?>

<div class="layui-container">
    <div class="layui-form-item layui-col-md8 layui-col-md-offset2">
        <blockquote class="layui-elem-quote">
            <span style="font-size:18pt;"> <?=$this->title?> </span> 重置密码会将该教师密码设为admin888 &nbsp; &nbsp;
            <button id='create' class="layui-btn layui-btn-normal">新增教师</button>
        </blockquote>
    </div>
    <div class="layui-form-item layui-col-md8 layui-col-md-offset2" style="border:1px solid #eee;border-top:0;margin-top:-25px;padding-top:50px;padding-bottom:50px;">
        <div style="width:80%;margin:auto">
            <table id="teachers" lay-filter="table_teachers">
            </table>
        </div>

    </div>
</div>
<!-- --工具条开始-- -->
<script id="resetAndDelete" type="text/html">
    <a class="layui-btn layui-btn-xs layui-btn-radius" lay-event="reset">&nbsp; 重置密码 &nbsp;</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-radius" lay-event="del">&nbsp; 删 除
            &nbsp;</a>
</script>
<!-- --工具条结束-- -->
<script language="javascript">
    layui.use(['element','form','table'], function () {
            let  $ = layui.$
                , form = layui.form
                , table = layui.table;
            $("#itemTeachers").addClass('layui-this'); //设置导航当前选中项的样式
            //begin_渲染教师管理表格
            table.render({
                elem: '#teachers'
                , id: 'teachers'
                , cols: [[
                    {field: 'name', width: 200, title: '用户名', sort: true, align: 'center'},
                    {field: 'realname', width: 200, title: '真实姓名', sort: true, align: 'center'},
                    {align: 'center',  toolbar: '#resetAndDelete', title: '操作'}
                ]]
                , url: '/super/getAllTeachers'
                , page: false
                , even: true //表格隔行换色

            });//end_渲染教师管理表格

            //begin_删除教师账号,重置密码
            table.on('tool(table_teachers)', function (obj) {
                if (obj.event === 'del') {
                    layer.confirm('真的删除该教师账号吗？', {icon: 3}, function (index) {
                        $.post('/super/deleteTeacher', {id: obj.data.id}, function () {
                            obj.del();
                            layer.close(index);
                        });
                    });
                }
                if (obj.event === 'reset') {
                    layer.confirm('真的要重置 <span style="color:red">' + obj.data['realname'] + ' </span>老师的登录密码吗？', {icon: 3}, function (index) {
                        $.post('/super/resetTeacherPassword', {id: obj.data.id}, function () {
                            layer.msg('成功，新密码是admin888');
                            layer.close(index);
                        });
                    });
                }
            });//end_删除教师账号,重置密码

            $('#create').click(function(){
                layer.open({
                    type:1
                    ,title: '<h3 style="color:#009688">➕ 添加教师账号</h3>'
                    , content: $('#divCreate')
                    , area: ['850px', '450px']
                });
                return false;
            });

             //Begin_增加教师账号
            form.on('submit(addTeacher)', function (data) {
                // console.log(data.field);
                $.post('/super/addTeacher',data.field,function (r){
                    console.log(r);
                    if (r==='<pre>新增成功！</pre>'){
                        layer.closeAll();
                        table.reload('teachers');
                    }
                    layer.msg(r);

                });
                return false;
            });
            //End_增加教师账号

        });
</script>
<?php include 'inc/super_foot.php';?>

<div id='divCreate' style="display: none;">
    <div style="height: 80px;">&nbsp;</div>
    <form action="" class="layui-form layui-form-pane">
    <div class="layui-form-item layui-col-md6 layui-col-md-offset3">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
        <input class="layui-input " lay-verify="required" name="name" placeholder="2-10位字符" type="text" />
        </div>
    </div>
    <div class="layui-form-item layui-col-md6 layui-col-md-offset3">
        <label class="layui-form-label">真实姓名</label>
        <div class="layui-input-block">
        <input class="layui-input" lay-verify="required" name="realname" maxlength='4' type="text" /></div>
    </div>
    <div class="layui-form-item layui-col-md6 layui-col-md-offset3">
        <label class="layui-form-label">密 码</label>
        <div class="layui-input-block">
        <input class="layui-input" lay-verify="required" name="password" placeholder="6-20位字符" type="text" /></div>
    </div>
    <div class="layui-form-item" style="text-align: center;">
        <button class="layui-btn" lay-filter="addTeacher" lay-submit="">
            确 定 新 增
        </button>
    </div>
</form>

</div>

